package cn.just.controller;

import cn.just.entity.Article;
import cn.just.entity.User;
import cn.just.service.ArticleService;
import cn.just.utils.THUtils;
import org.thymeleaf.context.Context;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author wujiaming
 */
@WebServlet(name = "ArticleServlet",value = "/ArticleServlet")
public class ArticleServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Context context = new Context();
        //将用户的信息填入页面中
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("user");
        context.setVariable("userName",user.getUserName());

        //获取请求参数
        String oId = request.getParameter("oId");
        System.out.println(oId);

        ArticleService articleService = new ArticleService();
        Article article = articleService.findById(Integer.parseInt(oId));

        context.setVariable("article",article);
        THUtils.write("blog/article",context,response);

    }
}
